from django.http import JsonResponse
from django.shortcuts import render, redirect, HttpResponse
from web import models
from web.forms.project import ProjectDeleteModelForm

def setting(request, project_id):
    return render(request, 'setting.html')

def setting_delete(request,project_id):
    if request.method == "GET":
        form =ProjectDeleteModelForm(request)
        return render(request,'setting_delete.html',{'form':form})
    xmid = request.POST.get('xmmc',"")
    if xmid:
        # ''' 删除当前账号创建的项目 '''
        delete_object = models.ProjectInfo.objects.filter(id=xmid,create_user=request.tracer.user).first()
        if delete_object:
            # 删除
            delete_object.delete()
            return JsonResponse({"status": True})
        return JsonResponse({"status": False,"errors":"项目不存在！"})
    return JsonResponse({"status":False,"errors":"请选择要删除的项目！"})